
import {

  getAssetTypeListApi,
  getEngineApuInfoListApi
} from '@/services/wingEngineAndApuInformation.js';

export default {
  namespaced: true,
  state: {
    getEngineApuInfoListLoading: false,
    engineApuInfoList: [],
    paginationOptions: {
      pageNum: 1,
      pageSize: 10,
      total: 10
    },
    assetTypeList: []
  },
  mutations: {
    setState(state, { key, payload }) {
      state[key] = payload;
    }
  },
  actions: {

    async getEngineApuInfoList({ commit, state, dispatch }, params) {
      commit('setState', { key: 'getEngineApuInfoListLoading', payload: true });
      const { pageNum, pageSize } = state.paginationOptions;
      const apiParams = {
        pageNum,
        pageSize,
        ...params
      };
      const rep = await getEngineApuInfoListApi(apiParams);
      commit('setState', { key: 'paginationOptions', payload: { ...state.paginationOptions, total: rep.data.total }});
      commit('setState', { key: 'engineApuInfoList', payload: rep.data.list });
      commit('setState', { key: 'getEngineApuInfoListLoading', payload: false });
    },
    async getAssetTypeList({ commit, state }) {
      const rep = await getAssetTypeListApi();
      commit('setState', { key: 'assetTypeList', payload: rep.data });
    }

  }
};
